<div class="modal fade bs-modal-md" id="modelContent">
	<div class="modal-dialog modal-md">
        <div class="modal-content"></div>
    </div>
</div> 
<div class="portlet box green">
	<div class="portlet-title">
	    <div class="caption"><i class="fa fa-cog"></i>查询内容 </div>
		<div class="tools">
			<a href="javascript:;" class="collapse right" data-original-title="" title=""> </a>
			<!-- <a href="" class="fullscreen" data-original-title="" title=""> </a> -->
    	</div>
    	<div class="actions">
			<a href="javascript:;" class="btn white btn-sm ajax-search"><i class="fa fa-search"></i> 查询 </a>
			<a href="javascript:;" class="btn white btn-sm search-reset"><i class="fa fa-eraser"></i> 清除 </a>
		</div>
	</div>
	<div class="portlet-body form">
	   	<form action="/companyMember/list" class="form-horizontal" method="get" id="searchForm" onsubmit="return false">
			<div class="form-body">
				<div class="row">
					<div class="form-group">
						<div class="col-md-3">
							<label class="col-md-4 control-label">所属企业：</label>
							<div class="col-md-8">
								<select class="form-control" name="companyId">
									<option value=" ">全体</option>
									#foreach($company in $!listCompany)
									<option #if($!companyId == $!company.id) selected #end value="$!company.id">$!company.name</option>
									#end
								</select>
							</div>
						</div>
						<div class="col-md-3">
							<label class="control-label col-md-4">会员号：</label>
							<label class="col-md-8">
								<input class="form-control" type="number"  max="2147483647" value="$!userId"  placeholder="输入会员号或手机号"  name="userId">
							</label>
						</div>
						<div class="col-md-3">
							<label class="control-label col-md-4">关联时间</label> 
							<label class="col-md-8">
								<input class="form-control" type="text" name="startTime" id="startTime" value="$!startTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
							</label>
						</div>
						<div class="col-md-3">
							<label class="control-label col-md-2">至：</label> 
							<label class="col-md-8">
								<input class="form-control" type="text" name="endTime" id="endTime" value="$!endTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
							</label>
						</div>
					</div>
					<div class="form-group">
						<div class="col-md-3">
							<label class="control-label col-md-4">负责人：</label>
							<label class="col-md-8">
								<select class="form-control" name="principal">
									<option value="">请选择</option>
									<option #if($!principal) selected #end value="true">是</option>
									<option #if(!$!principal) selected #end value="false">否</option>
								</select>
							</label>
						</div>
						<div class="col-md-3">
							<label class="control-label col-md-4">状态：</label>
							 <label class="col-md-8">
								<select class="form-control" name="companyState">
									<option value="">请选择</option>
									<option #if($!companyState == 1) selected="selected" #end value="1" >启用</option>
									<option  #if($!companyState == 0) selected="selected"  #end value="0" >禁用</option>
								</select>
							</label>
						</div>
					</div>
	    		</div>
			</div>
		</form>
	</div>
</div>
<div class="portlet box green">
    <div class="portlet-title">
		<div class="caption"><i class="fa fa-cogs"></i>数据列表</div>
		<div class="tools"><a href="javascript:;" class="collapse" data-original-title="" title=""> </a></div>
		<div class="actions">
			<a href="javascript:;" class="btn white btn-sm forbid-tab"><i class="fa fa-toggle-on"></i>禁用</a>
			<a herf="javascript:;" class="btn white btn-sm allowed-tab"><i class="fa fa-toggle-off"></i>启用</a>
   			<a thref="javascript:;" class="btn white btn-sm relieve-tab"><i class="fa fa-plus"></i>解除</a>
   			<a href="#modelContent" class="btn white btn-sm ajax-model-get "  data-toggle="modal"  thref="/companyMember/add"><i class="fa fa-edit" ></i>新增 </a>
   		</div>
    </div>
    <div class="portlet-body">
        <div class="form-group">
			<div class="alert alert-warning">
				<strong> 注：</strong>
				 被禁用的员工身份将临时转化为普通会员，也就是说不能使用信用支付为企业下单了。未实名会员不能成为企业负责人。
			</div>
		</div>
       	<div class="dataTables_wrapper no-footer">
			<div class="table-scrollable">
			    <table class="table table-striped table-bordered table-hover icheck-table">
				  	<thead>
						<tr>
							<th style="width: 20px">
								<input type="checkbox" class="icheck group-icheck" />
							</th>
		   		 			<th>公司名称</th>
		   		 			<th>部门</th>
		   		 			<th>会员号</th>
		   		 			<th>姓名</th>
							<th>手机号</th>
							<th>信用限额</th>
							<th>公众平台</th>
							<th>负责人</th>
							<th>状态</th>
							<th>关联日期</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
					 #foreach($userInfo in $!userInfoPage.result)
					 	#set($company =  $!companyMap.get($!userInfo))
					 	#set($department =  $!departmentMap.get($!userInfo))
					 	<tr>
					 		<td>
								<input type="checkbox" name="checkboxes" class="icheck" value="$!userInfo.id" />
							</td>
					 		<td>$!company.name</td>
					 		<td>$!department.title</td>
					 		<td>$!userInfo.id</td>
					 		<td>$!userInfo.realname</td>
					 		<td>$!userInfo.phone</td>
					 		<td>$!userInfo.creaditAmount</td>
					 		<td>$!userInfo.MemberSource</td>
					 		<td>#if($!company.userId == $!userInfo.id)
					 				<i class="fa fa-check font-green-jungle "></i>
								#else
								 	<i class="fa fa-close font-red-flamingo"></i>
								#end
							</td>
					 		<td>
					 			#if($!userInfo.companyState)
									<i class="fa fa-check font-green-jungle "></i>
								#else
								 	<i class="fa fa-close font-red-flamingo"></i>
								#end
							</td>
					 		<td>$!userInfo.bindingDate</td>
					 		<td>
					 		#if($!company.userId != $!userInfo.id) <a  href="javascript:vodi(0);" class="btn green btn-outline btn-sm ajax-delete"  thref="/companyMember/dalete?id=$!userInfo.id"><i class="fa fa-edit"></i>解除</a>  #end
					 		<a href="#modelContent" thref="/companyMember/add?id=$!company.id" class="btn green btn-outline btn-sm ajax-model-get" data-toggle="modal"><i class="fa fa-plus"></i> 新增 </a>
					 		</td>
					 	</tr>
					 #end
					</tbody>
				</table>
			</div>
			#set($page=$userInfoPage)
			#set($pageUrl="/companyMember/list?$!queryString&pageNo=")
			#parse("_page.htm")
		</div>
    </div>
</div>

<script src="/assets/scripts/views-date.js" type="text/javascript"></script>
<script type="text/javascript" src="/assets/scripts/views-icheck.js"></script>
<script type="text/javascript">
ComponentsSelect2.initWithSearch();
$("input[name=userId]").focus();

function getValues(){
	var array = new Array()
	var target= $("input[name='checkboxes']");
	//循环加入数组
	
		$.each(target,function(i,v){
			if(v.checked){
				array.push($(v).val());
			}
		});
	 	return array; 
	}
//批量禁用功能
$(".forbid-tab").click(function(){
	var arrayId = getValues();
	if(arrayId.length == 0){
		toastr.warning("请勾选您要禁用的会员！");
		return ;
	}
	bootbox.setLocale("zh_CN");
	bootbox.confirm("确定您要禁用这些会员？", function(state) {
			if (state) {
				$.post("/companyMember/editForbid", {
					"arrayId" : arrayId
				}, function(result) {
					if (result.code == 0) {
						toastr.success(result.msg);
						pageContentBody.load("/companyMember/list");
					} else {
						toastr.warning(result.msg);
					}
				}, "json");
			}
		});
});

//批量启用功能
$(".allowed-tab").click(function(){
	var arrayId = getValues();
	if(arrayId.length == 0){
		toastr.warning("请勾选您要启用的会员！");
		return ;
	}
	bootbox.setLocale("zh_CN");
	bootbox.confirm("确定您要启用这些会员？", function(state) {
			if (state) {
				$.post("/companyMember/allowed", {
					"arrayId" : arrayId
				}, function(result) {
					if (result.code == 0) {
						toastr.success(result.msg);
						pageContentBody.load("/companyMember/list");
					} else {
						toastr.warning(result.msg);
					}
				}, "json");
			}
		});
})


//解除会员
$(".relieve-tab").click(function(){
	var arrayId = getValues();
	if(arrayId.length == 0){
		toastr.warning("请勾选您要解除的会员！");
		return ;
	};
	bootbox.setLocale("zh_CN");
	bootbox.confirm("确定您要解除这些会员？", function(state) {
			if (state) {
				$.post("/companyMember/terminate", {
					"arrayId" : arrayId
				}, function(result) {
					if (result.code == 0) {
						toastr.success(result.msg);
						pageContentBody.load("/companyMember/list");
					} else {
						toastr.warning(result.msg);
					}
				}, "json");
			}
	});
	
})
</script>
